package models

import (
	"github.com/astaxie/beego/orm"
	"time"
	"github.com/astaxie/beego"
)

const MAXROWS  = 999999999
const APPROWS  = 10
type BaseModel struct{
	CreatedTime time.Time `orm:"auto_now_add;type(datetime)" json:"crated_time"`
	UpdatedTime time.Time `orm:"auto_now;type(datetime)" json:"updated_time"`
}
//[BUG]不稳定,结果数经常不对应...大概率是因为从池子拿出来的实例是新的连接
//只能做成事务
func GetTotal(o orm.Ormer) interface{}{
	var maps []orm.Params
	//o := GetSlaveDb()
	_, _ = o.Raw("select FOUND_ROWS() as amount").Values(&maps)
	beego.Warning(maps)
	return maps[0]["amount"]
}

func GetSlaveDb() orm.Ormer{
	o := orm.NewOrm()
	o.Using("slave")
	return o
}

func GetMasterDb() orm.Ormer{
	o := orm.NewOrm()
	o.Using("master")
	return o
}

